from tkinter import FLAT
import  music21 as ms21
import sys
fp=sys.argv[1]
s=ms21.converter.parseFile(sys.argv[1])#流输入
msgfilename=open(fp+"toMsg.txt","w+")
for a in s.flat:
	if isinstance(a, ms21.note.Note):
		print("n",a.pitch.midi,"{:1f}".format(float(a.duration.quarterLength)),a.measureNumber,file=msgfilename)
	elif isinstance(a, ms21.note.Rest):
		print("r",a.name,"{:1f}".format(float(a.duration.quarterLength)),a.measureNumber,file=msgfilename)
	elif isinstance(a, ms21.chord.Chord):
		print("c",end=" ",file=msgfilename)
		for cn in a.notes:
			print(cn.pitch.midi,end=" ",file=msgfilename)
		print("{:1f}".format(float(a.duration.quarterLength)),a.measureNumber,file=msgfilename)
	else:
		print("o",a,"{:1f}".format(float(a.duration.quarterLength)),a.measureNumber,file=msgfilename)
print("+",file=msgfilename)
msgfilename.close()